package work;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

public class StudentMapTest {
    public static void main(String[] args) {
        // 创建学生映射表对象
        Map<String,String> stu = new HashMap<>();
        // 添加学生
        stu.put("1001","张三");
        stu.put("1002","李四");
        stu.put("1003","王五");
        stu.put("1004","叶六");
        stu.put("1005","柳七");
        // 遍历输出
        stu.forEach(
                (id,name) -> System.out.println(id + ": " + name + " "));
        System.out.println("----------------------");
        // 根据学号查询学生信息
        System.out.println("学号为1002的学生: "+stu.get("1002"));



        System.out.println("----------------------");
        //创建学生TreeMap的对象
        Map<String,String> stuTree = new TreeMap<>(stu);
        // 遍历输出
        stuTree.forEach(
                (id,name) -> System.out.println(id + ": " + name + " "));
        System.out.println("----------------------");

    }
}
